# -*- shell-script -*-

# 40ibm,vpd - Hardware database scanning routines and variables for
#             systems with device-tree *and* ibm,vpd properties.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2002, 2003, 2004, 2005

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 40ibm,vpd,v 1.1 2006/04/11 18:38:28 emunson Exp $

[ "$device_tree_device_type" = "chrp" ] || return 0

######################################################################

# FIXME: This is a workaround to put this functionality back.  Getting
# this sort of functionality to work with hotplug will be more
# interesting.

extras_handlers="${extras_handlers} ibm_vpd_render_extras"
ibm_vpd_render_extras ()
{
    local i

    find "$source_device_tree" -name "ibm,vpd" |
    while read i ; do
 	local source_node="${i%/*}" # dirname
	local node="${db_bus_dt_dir}${source_node#${source_device_tree}}"
	local l="${node}/linux,vpd"

	# Render device-tree ibm,vpd if DB linux,vpd doesn't exist.
	if [ ! -d "$l" ] ; then
	    pci_render_vpd "$i" "$node"

	    # Handle FC and YL fields.
	    local fc=""
	    do_fc_hook "$source_node"
	    # Except at the root node, ensure there's a YL field.
	    local yl=""
 	    [ "$node" != "$db_bus_dt_dir" ] && \
		dt_manufacture_yl_hook "$source_node"

	    local vpd_subdirs
	    vpd_subdirs_list_hook "$node"

	    local vpd_dir
	    for vpd_dir in $vpd_subdirs ; do
 		[ -n "$yl" ] && \
 		    vpd_field_ensure "$vpd_dir" "YL" "$yl"
		[ -n "$fc" ] && \
		    vpd_field_override "$vpd_dir" "FC" "$fc"
	    done
	fi
    done
}
